/**
 * Project Name:SM Maven Webapp
 * File Name:SqlSession.java
 * Package Name:cn.sh.ideal.log.controller
 * Date:2015年3月5日下午2:34:02
 * Copyright (c) 2015, 上海理想信息产业（集团） All Rights Reserved.
 *
*/

package cn.sh.ideal.log.controller;

import javax.sql.DataSource;

import org.apache.ibatis.mapping.Environment;
import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import cn.sh.ideal.log.controller.db.mapping.ControllerLogMapper;

/**
 * ClassName:SqlSession <br/>
 * Function: TODO ADD FUNCTION. <br/>
 * Reason:	 TODO ADD REASON. <br/>
 * Date:     2015年3月5日 下午2:34:02 <br/>
 * @author   GengHongChuang
 * @version  
 * @since    JDK 1.6
 * @see 	 
 */
@Repository("logControllerSqlSession")
public class LogControllerSqlSession {
    @Autowired
    private LogControllerConfiguration logControllerConfiguration;
    
    public SqlSessionFactory getSessionFactory(){
        DataSource dataSource = logControllerConfiguration.getDataSource();

        Environment environment = new Environment("LogController", new JdbcTransactionFactory(), dataSource);
  
        Configuration configuration = new Configuration(environment);
    
        configuration.addMapper(ControllerLogMapper.class);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
        return sqlSessionFactory;
    }

    public LogControllerConfiguration getLogControllerConfiguration() {
        return logControllerConfiguration;
    }

    public void setLogControllerConfiguration(
            LogControllerConfiguration logControllerConfiguration) {
        this.logControllerConfiguration = logControllerConfiguration;
    }
    

}
